package br.com.jvet.util;

import java.io.Serializable;
import java.util.Date;

import org.apache.log4j.Logger;

public class Periodo implements Serializable {

	private static final long serialVersionUID = -6286292683840874817L;
	public static final Logger LOG = Logger.getLogger(Periodo.class.getName());
	private Date dataInicial;
	private Date dataFinal;

	public Periodo() {
		super();
		dataInicial = new Date();
		dataFinal = new Date();
	}

	public Periodo(Date dataInicial, Date dataFinal) {
		super();
		this.dataInicial = dataInicial;
		this.dataFinal = dataFinal;
	}

	@Override
	public Periodo clone() {

		Periodo p = new Periodo();

		p.setDataInicial(getDataInicial());

		p.setDataFinal(getDataFinal());

		return p;
	}

	public Date getDataInicial() {
		if (dataInicial == null)
			return null;
		return new Date(dataInicial.getTime());
	}

	public void setDataInicial(Date dataInicial) {
		this.dataInicial = dataInicial;
	}

	public Date getDataFinal() {
		if (dataFinal == null)
			return null;
		return new Date(dataFinal.getTime());
	}

	public void setDataFinal(Date dataFinal) {
		this.dataFinal = dataFinal;
	}

	public String toString() {
		StringBuffer str = new StringBuffer();

		str.append("DataInicial:" + dataInicial + "\n");
		str.append("DataFinal:" + dataFinal + "\n");

		return str.toString();
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((dataFinal == null) ? 0 : dataFinal.hashCode());
		result = prime * result
				+ ((dataInicial == null) ? 0 : dataInicial.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Periodo other = (Periodo) obj;
		if (dataFinal == null) {
			if (other.dataFinal != null)
				return false;
		} else if (!dataFinal.equals(other.dataFinal))
			return false;
		if (dataInicial == null) {
			if (other.dataInicial != null)
				return false;
		} else if (!dataInicial.equals(other.dataInicial))
			return false;
		return true;
	}

}
